﻿using System.Data.Entity.ModelConfiguration;
using INSE6260.OnlineBanking.Model.Accounts;
using System.ComponentModel.DataAnnotations;

namespace INSE6260.OnlineBanking.Repository.EF.Mappings
{
    public class AccountTypeConfiguration : EntityTypeConfiguration<Account>
    {

        public AccountTypeConfiguration()
        {					
    		this.HasKey(t => t.Id);		
    		this.ToTable("Account");
            //this.Property(t => t.Id).HasColumnName("Id").HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
    		this.Property(t => t.ClientId).HasColumnName("ClientId");
            this.Property(t => t.AccountNo).HasColumnName("AccountNo").IsRequired();
            this.Property(t => t.Balance).HasColumnName("Balance").IsRequired();
            this.Property(t => t.AvailableBalance).HasColumnName("AvailableBalance").IsRequired();
            this.Property(t => t.OpenDate).HasColumnName("OpenDate").IsRequired();
            this.Property(t => t.WPD).HasColumnName("WPD").IsRequired();
            this.Property(t => t.WPT).HasColumnName("WPT").IsRequired();
            this.Property(t => t.Status).HasColumnName("Status").IsRequired();
    		this.HasRequired(t => t.Client).WithMany(t => t.Accounts).HasForeignKey(d => d.ClientId);
            this.Map<CheckingAccount>(m => m.Requires("AccountType").HasValue("Checking"));
            this.Map<SavingAccount>(m => m.Requires("AccountType").HasValue("Saving"));
            this.Map<CreditAccount>(m => m.Requires("AccountType").HasValue("Credit"));
            this.Map<MoneyCardAccount>(m => m.Requires("AccountType").HasValue("Money Card"));
    	}
    }
}
